package campshop.daos;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import campshop.models.IpSchool;
public class IpSchoolDao extends JdbcDaoSupport{

	public boolean addIpSchoolByReplaceType(IpSchool is)
	{
		String sql = "replace into " +
				"tbl_ip_school (is_sIp, sr_uSchoolId)" +
				" values (?, ?)";
		if(super.getJdbcTemplate().update(sql, is.getsIp(), is.getuSchoolId())>0){
			return true;
		}else return false;
	}
	

	public IpSchool getIpSchool(long sIp)
	{
		String sql = "select * from tbl_ip_school where is_sIp=" + sIp;
		return (IpSchool)super.getJdbcTemplate().queryForObject(sql, new IpSchoolRowMapper());
	}
	class IpSchoolRowMapper implements RowMapper<IpSchool>{
		@Override
		public IpSchool mapRow(ResultSet rs, int rowNum) throws SQLException {
			IpSchool is = new IpSchool();
			is.setsIp(rs.getString("is_sIp"));
			is.setuSchoolId(rs.getLong("sr_uSchoolId"));
			return is;
		}	
	}
}